﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZHDJ.Data.Models.Center
{
    /// <summary>
    /// 组织关系转移公示
    /// </summary>
    public class PartyRelationnshipPublicity : EntityBase
    {
        public string LoginID { get; set; }
        public string StandID { get; set; }
        public string AppllicationID { get; set; }

        public string StepID { get; set; }

        public string Title { get; set; }

        public DateTime? CreateTime { get; set; }

        public string NoticeTime { get; set; }

        public string Category { get; set; }
        public static DataSet GetListData(int pageIndex, int pageSize)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(@" select SQL_CALC_FOUND_ROWS * FROM tblPartyRelationnshipPublicity 
                        ORDER BY CreateTime DESC ");

            if (pageIndex > -1)
            {
                sb.AppendFormat(" LIMIT {0} ,{1}; SELECT FOUND_ROWS(); ", pageIndex, pageSize);
            }
            return MySqlHelper.ExecuteDataSet(sb.ToString());
        }

        public static DataSet GetListDataByBranchID(int pageIndex, int pageSize, string branchId)
        {
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                 new MySqlParameter(){DbType = DbType.String,ParameterName = "BranchID",Value = branchId}
            };
            var sql = @"select SQL_CALC_FOUND_ROWS a.* FROM tblPartyRelationnshipPublicity a
                    left join tblpartyrelationshiptransfer b on a.AppllicationID = b.ID
                    where b.TageBranchID = ?BranchID or b.FormerBranchID = ?BranchID;
                    SELECT FOUND_ROWS();";

            return MySqlHelper.ExecuteDataSet(sql, para);
        }

        public static string GetListDataCount()
        {
            var sql = @"select Count(*) as count FROM tblPartyRelationnshipPublicity ";

            return MySqlHelper.ExecuteScalar(sql).ToString();
        }

        public static DataSet GetListDataByType(int pageIndex, int pageSize, string type)
        {
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "Begin",Value = (pageIndex)*pageSize},
                new MySqlParameter(){DbType = DbType.Int32,ParameterName = "PageSize",Value = pageSize},
                new MySqlParameter(){DbType = DbType.String,ParameterName = "StepID",Value = type}
            };
            var sql = @"select SQL_CALC_FOUND_ROWS * FROM tblpartyjoinpublicity 
                        where StepID = ?StepID  
                        ORDER BY CreateTime DESC LIMIT ?Begin ,?PageSize;
                        SELECT FOUND_ROWS();";

            return MySqlHelper.ExecuteDataSet(sql, para);
        }

        public static string GetListDataCountByType(string type)
        {
            MySqlParameter[] para = new MySqlParameter[]
            {
                new MySqlParameter(){DbType = DbType.String,ParameterName = "StepID",Value = type}
            };
            var sql = @"select Count(*) as count FROM tblpartyjoinpublicity where StepID = ?StepID";

            return MySqlHelper.ExecuteScalar(sql, para).ToString();
        }
    }
}
